﻿using QuocHoi_TV_Frontend.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace QuocHoi_TV_Frontend.Controllers
{
    public class ScheduleController : Controller
    {
        //
        // GET: /Schedule/

        public ActionResult ScheduleHome(string date, bool? active)
        {
            string dateW = DateTime.Now.ToString();
            if ((date == "") || (date == null))
            {
                date = dateW;
                active = false;
            }
            ViewData["active"] = active;
            ViewData["date"] = date;
            List<DateOfWeekItem> dateinweek = UtilDate.GetAlldayInWeek(DateTime.Parse(dateW));
            ViewBag.lstdateofweek = dateinweek;

            List<BroadcastDetail> schedule = DataModels.getBroadcastByDate(DateTime.Parse(date));
            if (Request.IsAjaxRequest())
                return PartialView("_ScheduleDate", schedule);
            return View(schedule);
        }

        [HttpPost]
        public ActionResult SessionOfDay(int? ib, string date)
        {
            string dateW = DateTime.Now.ToString();
            List<BroadcastDetail> schedule = new List<BroadcastDetail>();
            if ((date == "") || (date == null))
            {
                date = dateW;
            }
            ViewData["date"] = date;
            List<DateOfWeekItem> dateinweek = UtilDate.GetAlldayInWeek(DateTime.Parse(dateW));
            ViewBag.lstdateofweek = dateinweek;
            if (ib != null)
            {
                if (ib ==1)
                {
                    TimeSpan tspfrom =  new TimeSpan(0, 0, 0);
                    TimeSpan tspto = new TimeSpan(12, 0, 0);
                    schedule = DataModels.getBroadcastByDateSessionOfDate(DateTime.Parse(date), tspfrom, tspto);
                }
                else if (ib == 2)
                {
                    TimeSpan tspfrom = new TimeSpan(12, 0, 0);
                    TimeSpan tspto = new TimeSpan(23, 59, 0);
                    schedule = DataModels.getBroadcastByDateSessionOfDate(DateTime.Parse(date), tspfrom, tspto);
                }
                else
                {
                   schedule = DataModels.getBroadcastByDate(DateTime.Parse(date));
                }
            }
            else
            {
                schedule = DataModels.getBroadcastByDate(DateTime.Parse(date));
            }

            return PartialView("_ScheduleDate", schedule);
        }

    }
}
